﻿@inject IStringLocalizer<ValidateForms> Localizer

<ValidateForm Model="@Model" DisableAutoSubmitFormByEnter="true">
    <div class="row g-3">
        <div class="col-12 col-sm-6">
            <BootstrapInput @bind-Value="@Model.Name" />
        </div>
        <div class="col-12 col-sm-6">
            <BootstrapInput @bind-Value="@Model.Address" ValidateRules="@CustomerRules" />
        </div>
        <div class="col-12">
            <Button ButtonType="@ButtonType.Submit" Text="@Localizer["ValidateFormsSubmitButtonText"]" />
        </div>
    </div>
</ValidateForm>

@code {
    [NotNull]
    private Foo? Model { get; set; }

    private List<IValidator> CustomerRules { get; } = new();

    /// <summary>
    /// OnInitializedAsync 方法
    /// </summary>
    /// <returns></returns>
    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();

        // 切换线程 模拟异步通过 webapi 加载数据
        await Task.Yield();

        Model = new() { Name = "Name", Education = EnumEducation.Primary, DateTime = DateTime.Now };

        CustomerRules.Add(new FormItemValidator(new EmailAddressAttribute()));
    }
}
